<?php
class ARCommonQuestion extends CActiveRecord {
	public function tableName() {
		return '{{common_question}}';
	}
	
	public function rules(){
		return array(
			array('question, answer', 'length', 'min' => '2', 'max' => '1000'),
			array('question, answer', 'filter', 'filter' => 'htmlspecialchars'),
		);
	}
	
	public function attributeLabels() {
		return array('question' => '问题', 'answer' => '回答');
	}
	
	/**
	 * 快速写入问题答案
	 * @param string $question
	 * @param string $answer
	 */
	public function insertQuestion($question, $answer){
		$this->attributes = array('question' => $question, 'answer' => $answer);
		if($this->save()){
			return $this->getPrimaryKey();
		}
		return false;
	}
}